package com.zf.shuashua.ui.popup;

import android.app.Activity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.CenterPopupView;
import com.zf.shuashua.R;
import com.zf.shuashua.manager.AdAutoTouchManager;

/**
 * 余额不足
 */
public class LackBalancePopup extends CenterPopupView {

    private TextView btnTitle;
    private FrameLayout advert_container;
    private ImageView imgClose;
    private OnPopupListener mListener;
    private View view;

    public LackBalancePopup(@NonNull Activity context) {
        super(context);
    }

    public void setPopupListener(OnPopupListener listener) {
        this.mListener = listener;
    }

    public void addAdvertView(View view) {
        this.view = view;
        advert_container.removeAllViews();
        advert_container.addView(view);
        btnTitle.setVisibility(VISIBLE);
        imgClose.setVisibility(VISIBLE);
    }

    public void loadAdvertFail() {
        advert_container.setVisibility(GONE);
        btnTitle.setVisibility(VISIBLE);
        imgClose.setVisibility(VISIBLE);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.lack_balance;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        setupView();
    }

    private void setupView() {
        imgClose = findViewById(R.id.img_close);
        btnTitle = findViewById(R.id.btTitle);
        advert_container = findViewById(R.id.advert_container);

        btnTitle.setOnClickListener(v -> {
            if (!AdAutoTouchManager.getInstance().randomAutoClickAd(view)) {
                dismiss();
                if (mListener != null) {
                    mListener.onNext();
                }
            }
        });
        imgClose.setOnClickListener(v -> {
            dismiss();
        });
    }

}

